package com.xd.clap.controller;


import com.github.pagehelper.PageInfo;
import com.xd.clap.entity.GridOperator;
import com.xd.clap.entity.request.PageNumVO;
import com.xd.clap.entity.response.Result;
import com.xd.clap.services.GridOperatorService;
import com.xd.clap.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/grid")
public class GridOperatorController {

    @Autowired
    private GridOperatorService gridOperatorService;

    /**
     * 上传excel
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("/uploadExcel")
    public Result uploadExcel(@RequestParam MultipartFile file) throws IOException {
        ExcelUtil.importData(file);
        return Result.success("上传成功",null);
    }

    /**
     * 分页获取网格信息
     * @param pageNumVO
     * @return
     */
    @GetMapping("/getGrid")
    public Result getGrid(GridOperator gridOperator,PageNumVO pageNumVO){
        return gridOperatorService.getGrid(gridOperator,pageNumVO);
    }

    /**
     * 更新网格信息
     * @param gridOperator
     * @return
     */
    @PostMapping ("/updateGrid")
    public Result updateGrid(@RequestBody GridOperator gridOperator){
        return gridOperatorService.updateGrid(gridOperator);
    }

    /**
     * 添加网格信息
     * @param gridOperator
     * @return
     */
    @PostMapping ("/addGrid")
    public Result addGrid(@RequestBody GridOperator gridOperator){
        return gridOperatorService.addGrid(gridOperator);
    }

    /**
     * 删除网格信息
     * @param gridId
     * @return
     */
    @GetMapping("/deleteGrid")
    public Result deleteGrid(@Validated Integer gridId){
        return gridOperatorService.deleteGrid(gridId);
    }


    /**
     * 获取所有数据
     * @return
     */
    @GetMapping("/getGridAll")
    public Result getGridAll(){
        return gridOperatorService.getGridAll();
    }

}

